package com.company.common.auth;

import com.company.cloud.common.bean.LoginUserInfo;
import com.company.cloud.common.cache.CacheService;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.exception.BusinessException;
import com.company.cloud.common.redis.service.RedisUtils;
import com.company.common.auth.handle.AuthHandle;
import com.company.common.auth.handle.AuthHandleFactory;
import com.company.common.auth.util.SecurityUrlUtils;

public class AuthSecurityManager {


	/**
	 * 
	 * */
	public static LoginUserInfo check(String handleName, String url, String token, CacheService cacheService)
			throws BusinessException {
		AuthHandle handle = AuthHandleFactory.getAuthHandle(handleName);
		return handle.handle(token, url, cacheService);
	}
	
	
	/**
	 * 
	 * */
	public static LoginUserInfo check(String url, String token, CacheService cacheService) throws BusinessException {
		if (cacheService instanceof RedisUtils) {
			return SecurityUrlUtils.check(url, token, (RedisUtils)cacheService);
		}else {
			throw new BusinessException(BaseReturnEnum.Security_Config_Error);
		}
	}

}
